import re

str = """UDP outside  172.20.248.187:514 NP Identity Ifc  172.20.2.30:514, idle 0:00:17, bytes 946, flags - 
TCP mgmt  172.20.13.4:8078 NP Identity Ifc  172.20.52.35:22, idle 0:00:00, bytes 15391, flags UOB """

list = str.split('\n')

asa_dict = {}

for x in list:
    x = re.match('.*\s+ (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}) .*\s+ (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}).*bytes\s(\d+).*flags\s(.*)\s.*',x).groups()
    asa_key = x[0],x[1],x[2],x[3]
    asa_value = x[4],x[5]
    asa_dict[asa_key] = asa_value

print('打印字典:\n\n',asa_dict,sep='')
print('\n\n')
print('格式化打印输出:\n')

for key,value in asa_dict.items():
    print('{0:^5} : {1:15} | {2:^5} : {3:5} | {4:^5} : {5:15} | {6:^5} : {7:5}'.format('src',key[0],'scr_p',key[1],'dst',key[2],'des_p',key[3]))
    print('{0:^5} : {1:15} | {2:^5} : {3:5}'.format('bytes',value[0],'flags',value[1]))
    print('='*80)

"""
打印字典:

{('172.20.248.187', '514', '172.20.2.30', '514'): ('946', '-'), ('172.20.13.4', '8078', '172.20.52.35', '22'): ('15391', 'UOB')}



格式化打印输出:

 src  : 172.20.248.187  | scr_p : 514   |  dst  : 172.20.2.30     | des_p : 514  
bytes : 946             | flags : -    
================================================================================
 src  : 172.20.13.4     | scr_p : 8078  |  dst  : 172.20.52.35    | des_p : 22   
bytes : 15391           | flags : UOB  
================================================================================
"""